package deploy

import (
	"fmt"
	"github.com/urfave/cli/v2"
)

var (
	Kubeconfig string
	Group string
	NameSpace string
	Image string






	ArgumentErr string = "缺少必要参数%s\n"
)

func Deploy(c *cli.Context) error {
	if err := checkArgument(c); err != nil {
		return err
	}
	svc, err := NewK8sSvc()
	if err != nil {
		return err
	}
	return svc.RestartDeployment(NameSpace, Group, Image)
}

func checkArgument(c *cli.Context) error {
	if Kubeconfig = c.String("kubeconfig"); Kubeconfig == "" {
		return fmt.Errorf(ArgumentErr, "kubeconfig")
	}
	if Group = c.String("group"); Group == "" {
		return fmt.Errorf(ArgumentErr, "group")
	}
	if NameSpace = c.String("ns"); NameSpace == "" {
		return fmt.Errorf(ArgumentErr, "ns")
	}
	if Image = c.String("image"); Image == "" {
		return fmt.Errorf(ArgumentErr, "image")
	}
	return nil
}